#ifndef _MAIN_H_
#define _MAIN_H_

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <errno.h>
#include <time.h>

#include <math.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>

#include <libgen.h>

#include <pthread.h>

#include <sys/stat.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>

#include <netinet/in.h>

#include <prthread.h>
#include <prio.h> 
#include <prnetdb.h> 
#include <prinrval.h>
#include <prinit.h>
#include <prerror.h>
#include <prsystem.h>
#include <prmem.h>
#include <prtpool.h>
#include <prcvar.h>
#include <prlock.h>

#include <assert.h>

//#include <mysql/mysql.h>

#ifdef WITH_SYSLOG
#  include <syslog.h>
#endif

#ifdef WITH_EXECINFO
#  include <execinfo.h>
#endif


#include <dlfcn.h>



/***********************************************************************
** MACROS:      BEGIN_EXTERN_C
**              END_EXTERN_C
** DESCRIPTION:
**      Macro shorthands for conditional C++ extern block delimiters.
***********************************************************************/
#ifdef __cplusplus
# define BEGIN_EXTERN_C      extern "C" {
# define END_EXTERN_C        }
#else
# define BEGIN_EXTERN_C
# define END_EXTERN_C
#endif

BEGIN_EXTERN_C

#include "js.h"
#include "thread.h"
#include "eval.h"
#include "error.h"
#include "functions.h"

char *get_file_content_type(const char *filename);

void console_set_lock(unsigned char is_locked);


typedef int(* init_proc)(JSContext *, JSRuntime *);

int js_preprocess(char *buf, size_t len, FILE *stream);
int js_preprocess_string(char *buf, size_t len, char *str);
char *unescape(const char *buf);

//void trace(const char *fmt, ...);
char *read_stream(FILE *f, long *sz);
unsigned int *gen_primes(unsigned int n_max);
char *format_size(long);

int client(int argc, char **argv);
void *server(void *);
int daemonize(void);

#define TRUE 1
#define FALSE 0


#ifdef NODEBUG
# define trace2(x ...) 
# define trace1(ch, x ...) 
# define trace3(fmt, x)
# define trace trace2
#endif


END_EXTERN_C

#endif /* _MAIN_H_ */
